package com.controller;

import com.dao.TeacherDao;
import com.dto.DTO;
import com.entity.Teacher;
import com.page.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller //@Controller注解是用spring容器生成 对象 默认对象名 teacherController
@RequestMapping("/teacherController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /teacherController
public class TeacherController {
	@Resource
	TeacherDao teacherDao;
//	@RequestMapping("/getAllTeacher")
//	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
//    public DTO<Teacher> getAllTeacher(){
//    	System.out.println("查询全部教师");
//    	List<Teacher> teachers =  teacherDao.getAllTeachers();
//    	return new DTO<Teacher>(200, "查询全部教师",teachers);
//    }

	@RequestMapping("/deleteTeacherById/{aId}")
	@ResponseBody
    public DTO<Teacher> deleteTeacherById(@PathVariable("aId") String aId){//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(aId+"删除教师");
    	return new DTO<Teacher>(200, "删除"+aId+"教师成功");
    }


	@RequestMapping("/getTeacherByPage")
	@ResponseBody
	public DTO<Teacher> getTeacherByPage(PageInfo pageInfo){//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页教师");
		List<Teacher> teachers = teacherDao.getTeacherByPage(pageInfo);
		return new DTO<Teacher>(200, "分页查询教师成功",teachers);
	}

	@RequestMapping("/selectByTnoWithScs/{tno}")
	@ResponseBody
	public DTO<Teacher> selectByTnoWithScs(@PathVariable("tno")String tno){//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询教师授课");
		Teacher teacher = teacherDao.selectByTnoWithScs(tno);
		return new DTO<Teacher>(200, "分页查询教师成功",null,teacher);
	}

}
